package cn.weiyang.controller;

import cn.weiyang.model.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 用户业务控制器（结果返回json格式的数据）
 * Created by Administrator on 2017/7/24.
 */
@Controller
@RequestMapping("/user")
public class UserController {

    /*responsebody相当于规定了以json格式返回数据*/
    @ResponseBody
    @RequestMapping("/get")
    public String getUser(){
        return "{\"username\":\"张三\"}";
    }

    @ResponseBody
    @RequestMapping("/get1")
    public User getUser1(){
        User user=new User();
        user.setUsername("张三");
        user.setPassword("111");
        return user;
    }


    @ResponseBody
    @RequestMapping("/get2")
    public Map<String,Object> getUser2(User user){
        System.out.println(user);
        User user1=new User();
        user1.setUsername("张三");
        user1.setPassword("111");
        Map<String,Object> map=new HashMap<String, Object>();
        map.put("user",user1);
        return map;
    }

    @ResponseBody
    @RequestMapping("/get3")
    public List<User> getUser3(){
        User user1=new User();
        user1.setUsername("张三");
        user1.setPassword("111");
        List<User> list=new ArrayList<User>();
        list.add(user1);
        return list;
    }
}
